class Solution {
public:
    int maxSubArray(vector<int>& nums) {
        int ans=INT_MIN;
        int pre_sum=0;
        int min_pre_sum=0;
        for(int x:nums){
            pre_sum += x;
            ans=max(ans,pre_sum-min_pre_sum);
            min_pre_sum=min(min_pre_sum,pre_sum);
        }
        return ans;
    }
};
